package com.fiidee.blog.util;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 瑱彬 on 2015/5/27.
 */
public class DateUtil {
    public static Integer getNowInt(){
        Date date = new Date();
        Long timestamp = date.getTime();
        timestamp  = timestamp / 1000;
        int timeInt = timestamp.intValue();
        return timeInt;
    }

    public static Date intToDate(int timestamp){
        BigDecimal bd = new BigDecimal(timestamp);
        bd = bd.multiply(new BigDecimal(1000));
        long tlong = bd.longValue();
        Date date = new Date(tlong);
        return date;
    }

    public static String intToString(int timestamp,String format){
        Date date = intToDate(timestamp);
        DateFormat df = new SimpleDateFormat(format);
        return df.format(date);
    }

    public static void main(String[] args){
        String s = intToString(1432778372,"yyyy/MM/dd");
        System.out.println(s);
    }
}
